package com.zrwl.poscloud.core.task.message;

import com.zrwl.poscloud.xo.service.EmailService;
import com.zrwl.poscloud.xo.service.MessageService;
import io.swagger.annotations.ApiModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @author 刘思童
 * @create 2021/3/4 22:09
 **/
@Component
@ApiModel(value = "定时任务")
@Slf4j
public class MessageTask {


    @Autowired
    private MessageService messageService;

    @Autowired
    private EmailService emailService;

    // 每隔5秒执行一次
/*    @Scheduled(fixedDelay = 5000)
    protected void sendSms() {
        log.info("短信发送: " + LocalDateTime.now());
        messageService.sendSms();
    }*/

    // 每隔10秒执行一次
/*    @Scheduled(fixedDelay = 10000)
    protected void sendWx() {
        Calendar cal= Calendar.getInstance();
        log.info("微信消息发送: " + LocalDateTime.now());
        messageService.sendWx();
    }*/
     // 每隔60秒执行一次
/*    @Scheduled(fixedDelay = 5000)
    protected void sendEmail() {
        log.info("Email发送: " + LocalDateTime.now());
        emailService.sendEmail2();
    }*/
    //短信验证码 每3分钟发送一次 0 0/3 * * * ?
    @Scheduled(cron = "0/5 * * * * ? ")
    protected void sendSms() {
        log.info("短信验证码发送: " + LocalDateTime.now());
        messageService.sendMessage(1,1);
    }
    //8点到20点每5分钟发送一条微信消息"0 0/5 8-20 1/1 * ?
/*    @Scheduled(cron = "0 0/5 8-20 1/1 * ? ")
    protected void sendAccountBalanceTasks() {
        System.out.println("定时发送账户余额不足提醒");
        messageService.sendMessage(2,2);
    }*/
    //8点到20点每5分钟发送一条微信消息0 0/5 8-20 1/1 * ?
/*    @Scheduled(cron = "0 0/5 8-20 1/1 * ? ")
    protected void sendResourceBalanceTask() {
        System.out.println("定时发送资源余量不足提醒");
        messageService.sendMessage(2,8);
    }*/
}
